package org.redis.cluster.admin.slot.controller;

import java.util.Collection;

import org.redis.cluster.admin.Constants;
import org.redis.cluster.admin.result.Result;
import org.redis.cluster.admin.result.ResultBuilder;
import org.redis.cluster.admin.slot.model.SlotInfo;
import org.redis.cluster.admin.slot.service.SlotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(Constants.API_ROOT+"/slot")
public class SlotController {

	@Autowired
	private SlotService slotService;
	
	/**
	 * @return
	 */
	@RequestMapping(value="/count",method=RequestMethod.GET)
	public Result getSlotCount() {
		int count=slotService.getSlotCount();
		return ResultBuilder.success(count);
	}
	
	/**
	 * @return
	 */
	@RequestMapping(value="",method=RequestMethod.GET)
	public Result getSlots() {
		Collection<SlotInfo> infos=slotService.getInfos();
		return ResultBuilder.success(infos);
	}
}